//
//  ZqlMainController.swift
//  ZqlSinaWeiBo
//
//  Created by 赵乾龙 on 16/1/30.
//  Copyright © 2016年 Mr.zhao. All rights reserved.
//

import UIKit

class ZqlMainController: UITabBarController {
    
    //方法前加@objc 意思是告诉运行循环 此方法是基于OC的
    @objc private func plusBtnDidClick() {
        let composeVC = ZqlcomposeVC()
        let nav = ZqlBaseNavVC(rootViewController:composeVC)
        presentViewController(nav, animated: true, completion: nil)
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabBar=ZqlMainTabar()
        setValue(mainTabBar, forKey: "tabBar")
        let actionName = "plusBtnDidClick"
        
        mainTabBar.plusBtn.addTarget(self, action: Selector(actionName), forControlEvents: .TouchUpInside)
        
        addChildViewControllers()
    }
    
    //设置各个控制器
    private func addChildViewControllers(){
        addChildViewController(ZqlHomeController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(ZqlMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(ZqlDiscoverController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(ZqlProfileController(), title: "我", imageName: "tabbar_profile")
    }
    
    
    //添加控制器的方法
    private func addChildViewController(VC: UIViewController,title:String,imageName:String) {
        
        //设置渲染颜色
        tabBar.tintColor=UIColor.orangeColor()
        
        let nav=ZqlBaseNavVC(rootViewController: VC)
        VC.title=title
        VC.tabBarItem.image=UIImage(named: imageName)
        
        addChildViewController(nav)
        
    }
    
    
}
